<?php
/**
 * Created by PhpStorm.
 * User: shaowei
 * Date: 2019/4/23
 * Time: 下午3:37
 */

namespace App\Http\Controllers;


use App\Http\Model\OutJson;
use App\Http\Services\RoomExpServices;
use App\Http\Services\RoomMsgServices;
use Illuminate\Http\Request;
use App\Http\Model\Hint;
use App\Lib\Response;

class RoomExpController extends Controller
{
    private $servicesRoomMsg;
    private $servicesRoomExp;

    public function __construct(RoomMsgServices $roomMsgServices, RoomExpServices $roomExpServices)
    {
        $this->servicesRoomMsg = $roomMsgServices;
        $this->servicesRoomExp = $roomExpServices;
    }


    /**
     * 发送特殊表情 骰子、举牌
     */
    public function sendSpecial(Request $request){
        $roomId = $request->post('room_id');
        $type = $request->post('type');
        if (empty($roomId) || empty($type)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $userId = null;
        $resId = 0;
        if ($type == 1){
            $resId = $this->servicesRoomExp->makeDice($roomId, $userId);
        }
        if ($type == 2){
            $resId = $this->servicesRoomExp->makeCard($roomId, $userId);
        }
        if (empty($resId)){
            Response::returnResult(Hint::ERROR);
        }
        if ($resId == Hint::LOGIN_OUT){
            Response::returnResult(Hint::LOGIN_OUT);
        }
        $this->servicesRoomMsg->broadcastExp($roomId, $userId, $resId);
        Response::returnResult(Hint::SUCCESS);
    }
}